package jgcp.worker.monitor;

/**
 * @author Peng Zhang
 */

import org.hyperic.sigar.CpuPerc;
import org.hyperic.sigar.Mem;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.Swap;

public class WorkerMonitor {
	
	public double cpuUsage;
	public int memFree ;
	public int memTotal ;
	
	public void retrieveSystem(){
		try {
			Sigar sigar = new Sigar();
			CpuPerc perc = sigar.getCpuPerc();
			Mem mem = sigar.getMem();
			Swap swap = sigar.getSwap();
			
			cpuUsage = perc.getCombined();
			memFree = (int)(mem.getFree()/(1024l*1024l));
			memTotal = (int)(mem.getTotal()/(1024l*1024l));

		}catch (Exception e){
			
		}
	}
	public static void main(String[] args) {
		WorkerMonitor wm = new WorkerMonitor();
		wm.retrieveSystem();
		System.out.println("CPU Usage:"+wm.cpuUsage);
		System.out.println("Free Memory:"+wm.memFree);
		System.out.println("Total Memory:"+wm.memTotal);
		
	}
	
	


}
